The most pythonic way of handling exceptions